package com.cdream.basic.algorithm.leetcode.string;

/**
 * @author cdream
 * @date 2021/10/4
 */
public class Question482 {
    public String licenseKeyFormatting(String s, int k) {

        s = s.replaceAll("-","");
        if (s.length()==0){
            return "";
        }
        int firstLength = s.length() % k;
        if (firstLength == 0) {
            firstLength = k;
        }
        StringBuilder sb = new StringBuilder(s.substring(0,firstLength));
        while (firstLength!=s.length()){
            sb.append("-");
            sb.append(s, firstLength, firstLength+k);
            firstLength+=k;
        }
        return sb.toString().toUpperCase();

    }
}
